﻿using UnityEngine;
using System.Collections;

public class WeaponMachineGun : WeaponInterface {

	public GameObject bulletPrefab;
	public float cooldownTimeInS = 0.2f;

	protected float cooldownTimerInS = 0.0f;
	// Use this for initialization
	void Start () {
	
	}
	
	// Update is called once per frame
	void Update () {
		if (cooldownTimerInS > -0.001f) {
			cooldownTimerInS -= Time.deltaTime;
		}
	}

	override public void Fire (Vector3 direction) {
		Debug.Log("MachineGun Fire.");
		if (bulletPrefab && cooldownTimerInS < 0.0f) {
			GameObject bullet = Instantiate<GameObject>(bulletPrefab);
			cooldownTimerInS = cooldownTimeInS;
			Bullet bulletComponent = bullet.GetComponent<Bullet>();
			if (bulletComponent) {
				bulletComponent.SetTarget(TargetTag);
				bulletComponent.Lunch(gameObject.transform.position, gameObject.transform.forward);
			}
		}
	}
}
